package pl.mchaniewski.ryneczek.utilities;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtil {
    public static UserDetails getUserDetails() {
        Authentication auth = SecurityContextHolder.getContext()
                .getAuthentication();

        Object obj = (auth == null) ? null : auth.getPrincipal();
        if (obj != null) {
            if (obj instanceof UserDetails) {
                return (UserDetails) obj;
            }
        }

        return null;
    }

}
